package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.DrugPurchaseRecordDao;
import com.jiantong.work.impl.manager.DrugPurchaseRecordManager;


import com.jiantong.work.model.DrugPurchaseRecord;
import com.jiantong.work.service.DrugPurchaseRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by maowenjie on 2017/4/17.
 */
@Slf4j
@Service
@RpcProvider
public class DrugPurchaseRecordWriteServiceImpl implements DrugPurchaseRecordWriteService {
    private final DrugPurchaseRecordManager drugPurchaseRecordManager;
    private final DrugPurchaseRecordDao drugPurchaseRecordDao;

    public DrugPurchaseRecordWriteServiceImpl(DrugPurchaseRecordManager drugPurchaseRecordManager, DrugPurchaseRecordDao drugPurchaseRecordDao) {
        this.drugPurchaseRecordManager = drugPurchaseRecordManager;
        this.drugPurchaseRecordDao = drugPurchaseRecordDao;
    }

    @Override
    public Response<Map<String, Object>> createDrugPurchaseRecord(DrugPurchaseRecord drugPurchaseRecord, Integer toStatus) {
        try {
            return Response.ok(drugPurchaseRecordManager.createDrugPurchaseRecord(drugPurchaseRecord, toStatus));
        } catch (Exception e) {
            log.error("failed to create disinfectReport  error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("create.disinfectReport");
        }
    }

    @Override
    public Response<Map<String, Object>> updateDrugPurchaseRecord(DrugPurchaseRecord drugPurchaseRecord, Integer toStatus) {
        try {
            return Response.ok(drugPurchaseRecordManager.updateDrugPurchaseRecord(drugPurchaseRecord, toStatus));
        } catch (Exception e) {
            log.error("failed to update drugPurchaseRecord  error:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("update.drugPurchaseRecord");
        }
    }

    @Override
    public Boolean update(DrugPurchaseRecord drugPurchaseRecord) {
        return drugPurchaseRecordDao.update(drugPurchaseRecord);
    }


}

